package com.future.serverwhiteborad.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author lihao
 * @date 2021/5/24/16:35
 * netty服务端
 */
public class NettyServer {
    /**
     * 流程   创建线程组----->选择io模型----->处理逻辑----->绑定端口
     * @param args
     */
    public static void main(String[] args) {
        //监听客户端请求线程组
        NioEventLoopGroup bossGroup = new NioEventLoopGroup();
        //处理每条连接的数据读写线程组
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();
        //服务端启动引导类
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap
                .group(bossGroup, workerGroup)
                //io模型选择
                .channel(NioServerSocketChannel.class)
                //配置每条连接的数据读写和业务逻辑
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) {
                        System.out.println("服务端启动中！。。。。。。。。。。。");
                    }
                });
        //绑定端口
        serverBootstrap.bind(8000);
    }
}


 
    